/*******************************************************************************
 * Copyright 2007, 2009 InnovaSoft SA http://www.innovasoft.biz/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/

package biz.innovasoft.ndb.index;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.CharStream;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.queryParser.QueryParserTokenManager;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.RangeQuery;

import biz.innovasoft.ndb.util.IndexUtils;

public class ExtendedQueryParser extends QueryParser {

	public ExtendedQueryParser(CharStream stream) {
		super(stream);
	}

	public ExtendedQueryParser(QueryParserTokenManager manager) {
		super(manager);
	}

	public ExtendedQueryParser(String query, Analyzer analyzer) {
		super(query, analyzer);
	}

	public Query newRangeQuery(String field, String part1, String part2,
			boolean inclusive) {
		try {
			int num1 = Integer.parseInt(part1);
			int num2 = Integer.parseInt(part2);
			return new RangeQuery(new Term(field, IndexUtils.format(num1)),
					new Term(field, IndexUtils.format(num2)), inclusive);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return super.newRangeQuery(field, part1, part2, inclusive);
	}
}
